package com.creditharmony.car.loan.service.impl;

import java.util.Date;
import java.util.UUID;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.creditharmony.car.common.base.service.impl.BaseServiceImpl;
import com.creditharmony.car.loan.dao.CarLoanStatusHisDao;
import com.creditharmony.car.loan.entity.CarLoanStatusHisEntity;
import com.creditharmony.car.loan.service.CarHistoryService;


/**
 * 借款历史
 * @Class Name CarCustomerService
 * @author 刘振杰
 * @Create In 2017年12月7日
 */
@Service
public class CarHistoryServiceImpl extends BaseServiceImpl<CarLoanStatusHisEntity> implements CarHistoryService {
    @Autowired
    private CarLoanStatusHisDao carLoanStatusHisDao;

    /**
     * 添加操作历史
     * 
     * @param loanCode
     *            借款编码
     * @param operateStep
     *            操作步骤code（节点code，参考CarLoanSteps）
     * @param operateResult
     *            操作结果（路由）
     * @param remark
     *            备注
     * @param loanStatusCode
     *            借款状态编码（参考CarLoanStatus）
     * @return
     */
    public int saveCarLoanStatusHis(String loanCode, String operateStep, String operateResult, String remark,
            String loanStatusCode) {
        CarLoanStatusHisEntity record = new CarLoanStatusHisEntity();
        record.setId(UUID.randomUUID().toString().replace("-", ""));
        // APPLY_ID
        record.setLoanCode(loanCode);
        // 操作节点，如上传资料、初审、终审等的code值
        record.setOperateStep(operateStep);
        // 操作结果，用中文表示，如初审通过，终审拒绝等
        record.setOperateResult(operateResult);
        // 备注
        record.setRemark(remark);
        // 借款状态，当前节点操作后的状态code值
        record.setDictLoanStatus(loanStatusCode);
        // 系统标识
        // record.setDictSysFlag(ModuleName.MODULE_LOAN.value);
        // 操作时间
        record.setOperateTime(new Date());
        record.setCreateTime(new Date());
        // User user = UserUtils.getUser();
        // if (user != null) {
        // record.setOperator(user.getName());// 操作人记录当前登陆系统用户名称
        // if (!ObjectHelper.isEmpty(user)) {
        // record.setOperatorRoleId(user.getId());// 操作人角色
        // }
        // if (!ObjectHelper.isEmpty(user.getDepartment())) {
        // record.setOrgCode(user.getDepartment().getId()); // 机构编码
        // }
        // }
        return carLoanStatusHisDao.insert(record);
    }
}
